//
//  VisitView.swift
//  firstSwiftWeiBo
//
//  Created by Inverno on 16/12/5.
//  Copyright © 2016年 Inverno. All rights reserved.
//

import UIKit

class VisitView: UIView {
    
    @IBOutlet weak var turntable: UIImageView!
    @IBOutlet weak var logoView: UIImageView!
    
    var needRotate = false {
        didSet {
            
            turntable.hidden = !needRotate
            
            if needRotate {
                
                let animation = CABasicAnimation()
                
                animation.duration = 5.0
                animation.repeatCount = MAXFLOAT
                animation.keyPath = "transform.rotation.z"
                animation.fromValue = 0
                animation.toValue = 2 * M_PI
                animation.removedOnCompletion = false
                
                turntable.layer.addAnimation(animation, forKey: nil)
            }
        }
    }
    
    // 创建类方法
    class func visitView() -> VisitView {
        let visitView = NSBundle.mainBundle().loadNibNamed("VisitView", owner: nil, options: nil).first as! VisitView
        
        return visitView
    }
    
    func setup(imageName name : String) {
        logoView.image = UIImage(named: name)
    }
    
}
